package com.ws.game.lesson3.fire
{
	import com.ws.game.common.framework.BaseCtrl;
	import com.ws.game.common.global.Global;
	import com.ws.game.common.utils.PartType;
	
	import flash.display.Sprite;
	
	public class Monster extends FaceObject implements IShoot
	{
		private var _lastAction:Date;
		private var _fps:uint = 8;
		
		public function Monster(aCtrl:BaseCtrl, face:Sprite)
		{
			super(aCtrl, face);		
			this._part = PartType.MONSTER;
			this.speed = 1;
			_lastAction = new Date();
		}
		
		/**
		 * IShoot interface
		 * 
		 * */
		public function shoot():void{			
			var b:Bullet = new Bullet(this);
			b.x = x+width/2;
			b.y = y+height/2;
			Global.scene.addGameObject(b);
		}
		
		override public function doWork():void{
			var date:Date = new Date();
//			 如果运行时间已经超过频率所指定的时间间隔，那么运行程序
			if (date.time-_lastAction.time > 1000/_fps)
			{
				_lastAction = date;
				this.ctrl.autoRun();
				super.doWork();
			}
		}
	}
}